import OpenAI from 'openai';

const openai = new OpenAI({
//   apiKey: process.env['ARK_API_KEY'],
  apiKey:"4c81ddcd-1d09-44a0-9090-a4c2b65c356f",
  baseURL: 'https://ark.cn-beijing.volces.com/api/v3',
});

async function main() {
  // Non-streaming:
  console.log('----- standard request -----')
  const completion = await openai.chat.completions.create({
    messages: [
      { role: 'system', content: '你是人工智能助手' },
      { role: 'user', content: '常见的十字花科植物有哪些？' },
    ],
    // model: '{TEMPLATE_ENDPOINT_ID}',
    model:'deepseek-v3-250324',
  });
  console.log(completion.choices[0]?.message?.content);

  // Streaming:
//   console.log('----- streaming request -----')
//   const stream = await openai.chat.completions.create({
//     messages: [
//       { role: 'system', content: '你是人工智能助手' },
//       { role: 'user', content: '常见的十字花科植物有哪些？' },
//     ],
//     model: '{TEMPLATE_ENDPOINT_ID}',
//     stream: true,
//   });
//   for await (const part of stream) {
//     process.stdout.write(part.choices[0]?.delta?.content || '');
//   }
//   process.stdout.write('\n');
}

main();